<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body id="demo">
        <p>姓名：<input type="text"></p>
        <p id="two">年龄：<input type="text"></p>    
        <p>电话：<input type="text"></p>
        <p>住址：<input type="text"></p>
        <p><button>确定</button></p>
</body>
<script>
    var demo = document.getElementById('demo');
    var tw = document.getElementById('two');
    var p = document.createElement('p');
    var txt = document.createTextNode('性别：');
    var input = document.createElement('input');
    
    p.id = 'sex';
    p.appendChild(txt);
    p.appendChild(input);
    demo.insertBefore(p,tw);






    var num = demo.childNodes;
    console.log(num)
   
    console.log('body的子元素节点一共有'+num.length+'个');
    // for (let index = 0; index < num.length; index++) {
    //     console.log('第'+index+'个的节点是'+num[index].nodeName)
        
    // }

    num.forEach((item,index)=>{
        console.log('第'+index+'个的节点是'+item.nodeName)
    })
</script>

</html>